package com.example.demo.Controller;



import com.example.demo.Entity.Node;
import com.example.demo.Entity.RqstBd;
import com.example.demo.Entity.RtnBd;
import com.example.demo.Repository.NodeRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.net.CookieManager;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@RestController
public class InfoController {

    @Autowired
    private NodeRepository nodeRepository;

    @RequestMapping(value = "/customer/homePage",method = RequestMethod.POST)
    public RtnBd findAllMenu(@RequestBody RqstBd rqstBd) {
        System.out.println("received a request");
        String a="";
        RtnBd rtnBd = new RtnBd();
        if("rels_symptom".equals(rqstBd.relation)){
            a = nodeRepository.findCauseByDisease(rqstBd.input);
            rtnBd.setResult(a);
        }
        if("rels_doeat".equals(rqstBd.relation)){
            String []results = nodeRepository.DiseaseDoEat(rqstBd.input);
            rtnBd.setrList(results);
        }
        if("rels_category".equals(rqstBd.relation)){
            String []results = nodeRepository.DiseaseCategory(rqstBd.input);
            rtnBd.setrList(results);
        }
        System.out.println(rqstBd);
        System.out.println(rtnBd.toString());

        return rtnBd;
    }

}

